package CMD;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;

public class CMD {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<String> path = new ArrayList<>();
        path.add("C:");
        path.add("\\Users");
        path.add("\\lenovo");
        Instruction.showPath(path);
        //显示初始路径

        //进行操作
        while(true){
            String input = sc.nextLine();
            char a[] = input.toCharArray();
            int index = a.length - 1;
            for(int i = 0; i < a.length; i++) {
                if(a[i] == ' '){
                    index = i;
                    break;
                }
            }
            String operation = input.substring(0,index);
            String operationContent = input.substring(index + 1,input.length());
            switch (operation.toLowerCase()){
                case "cd" -> Instruction.cdOperation(operationContent,path);
                case "touch" -> Instruction.touchOperation(operationContent,path);
                case "delete" -> Instruction.deleteOperation(operationContent,path);
                case "mkdir" -> Instruction.mkdirOperation(operationContent,path);
                case "mv" -> Instruction.moveOperation(operationContent,path);
                case "ls" -> Instruction.showAllFiles(path);
                case "cat" -> Instruction.readFile(operationContent,path);
                case "write" -> Instruction.writeFile(operationContent,path);
                case "exit" -> {
                    System.out.println("程序结束");
                    System.exit(0);
                }
                default -> {
                        System.out.println("' " + operation + " '" +
                                " 不是内部或外部命令，也不是可运行的程序 或批处理文件。");
                    Instruction.showPath(path);
                }
            }
        }
    }
}
